﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DetectScars.common
{
    internal class AosInterface
    {

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void CallbackDelegate(string msg);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void CallbackDelegate_Connect(string msg);



        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void CallbackDelegate_Acquisition(IntPtr ptr,int rows,int cols, Int32 en1,int flag, Int32 en2);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void CallbackDelegate_Ccquisition(IntPtr ptr, int rows, int cols, Int32 en1, int flag, Int32 en2);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void CallbackDelegate_Bcquisition(IntPtr ptr, int len,int row);



        [DllImport("ut-aos-cpp.dll", EntryPoint = "createDevice", CallingConvention = CallingConvention.Cdecl)]
        public static extern string createDevice(string json);

        public static void createDevice_messagebox(string json)
        {
            string msg = createDevice(json);
            if(msg != "" &&  msg != "1") { 
                MessageBox.Show("异常");
            }
        }

        [DllImport("ut-aos-cpp.dll", EntryPoint = "testd", CallingConvention = CallingConvention.Cdecl)]
        public static extern string testd(string json);

        [DllImport("ut-aos-cpp.dll", EntryPoint = "register_callback_error_message", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int register_callback_error_message(CallbackDelegate callback);

        [DllImport("ut-aos-cpp.dll", EntryPoint = "register_callback_hardware_status", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int register_callback_hardware_status(CallbackDelegate_Connect callback);


        [DllImport("ut-aos-cpp.dll", EntryPoint = "startDevice", CallingConvention = CallingConvention.Cdecl)]
        public static extern void startDevice();

        [DllImport("ut-aos-cpp.dll", EntryPoint = "register_callback_acquisition", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int register_callback_acquisition(CallbackDelegate_Acquisition callback);

        [DllImport("ut-aos-cpp.dll", EntryPoint = "stopDevice", CallingConvention = CallingConvention.Cdecl)]
        public static extern void stopDevice();


        [DllImport("ut-aos-cpp.dll", EntryPoint = "register_callback_ccquisition", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int register_callback_ccquisition(CallbackDelegate_Ccquisition callback);


        [DllImport("ut-aos-cpp.dll", EntryPoint = "register_callback_image_result", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int register_callback_image_result(CallbackDelegate_Bcquisition callback);

    }
}
